*******************************************************************************
******************************  FIGURE 1  *************************************
******* Women's Influence and Authority by Group Gender Composition ***********
*******************************************************************************


clear all
set more off

//cd "C:/Users/ganth/Dropbox/StrengthInNumbersReplicationPackage/replicable/figure_1"

********************************************************************************

***Figure 1a***

**Study 1 Analysis

foreach var in genderminfl_labavg_ratio genderlinfl_labavg_ratio {
    use "figure_1_dataset_1.dta", clear
	reg `var' b3.fall_condition, robust
	margins fall_condition, post
	estimates store margins
	test _b[1bn.fall_condition] = _b[3.fall_condition]
	outreg2 margins using "intermediate_data/study1_group`var'.dta", replace dta side noparen noas

	ttest `var', by(fall_condition)
	putexcel set "intermediate_data/study1_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/study1_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	gen ci=v3*1.96
	export delimited "intermediate_data/study1_group`var'_forgraphing.csv", replace
}

**Study 2 Analysis

foreach var in genderminfl_ratio_r1 genderlinfl_ratio_r1 {
    use "figure_1_dataset_2.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/study2_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/study2_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/study2_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/study2_group`var'_forgraphing.csv", replace
}

**Combined Analysis
	
foreach var in genderminfl_ratio_ravg genderlinfl_ratio_ravg {
    use "figure_1_dataset_3.dta", clear
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/combined_group`var'.dta", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/combined_group`var'_1p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (1.15)
	*putexcel save

	use "intermediate_data/combined_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/combined_group`var'_forgraphing.csv", replace
	drop ci
	rename (v1 v2 v3) (condition val se)
	ssc install texsave
	texsave * using "intermediate_data/jpe_figure_1_table_`var'.tex", replace
}

clear

***Figure 1b***
**Study 1 Analysis
use "figure_1_dataset_1.dta", clear
reg genderspokes_labavg_ratio b3.fall_condition if fall_condition~=2, robust
margins fall_condition, post
estimates store margins
test _b[1bn.fall_condition] = _b[3.fall_condition]
outreg2 margins using "intermediate_data/study1_groupgenderspokes_labavg_ratio.dta", replace dta side noparen noas

ttest genderspokes_labavg_ratio if fall_condition==1 | fall_condition==3, by(fall_condition)
putexcel set "intermediate_data/study1_groupgenderspokes_labavg_ratio_2p.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = (r(mu_1)+(r(sd)))


use "intermediate_data/study1_groupgenderspokes_labavg_ratio_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1bn.fall_condition"
replace v1="Majority Female" if v1=="3.fall_condition"
gen ci=v3*1.96
export delimited "intermediate_data/study1_groupgenderspokes_labavg_ratio_forgraphing.csv", replace


**Study 2 Analysis
use "figure_1_dataset_2.dta", clear
reg genderspokes_ratio_r1 i.condition_2f, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/study2_genderspokes_ratio_r1.dta", replace dta side noparen noas

ttest genderspokes_ratio_r1 if condition_2f==0 | condition_2f==1, by(condition_2f)
putexcel set "intermediate_data/study2_genderspokes_ratio_r1_2p.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = (r(mu_1)+(r(sd)))

use "intermediate_data/study2_genderspokes_ratio_r1_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/study2_genderspokes_ratio_r1_forgraphing.csv", replace


**Combined Analysis
use "figure_1_dataset_3.dta", clear
reg genderspokes_ratio_ravg i.condition_2f, robust
margins condition_2f, post
estimates store margins
test _b[1.condition_2f] = _b[0.condition_2f]
outreg2 margins using "intermediate_data/combined_genderspokes_ratio_ravg.dta", replace dta side noparen noas

ttest genderspokes_ratio_ravg if condition_2f==0 | condition_2f==1, by(condition_2f)
putexcel set "intermediate_data/combined_genderspokes_ratio_ravg_2p.xlsx", sheet("t_test") replace
putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
putexcel A2 = (0.75)
putexcel B2 = (2.25)
putexcel C2 = (round(r(p), 0.001))
putexcel D2 = (r(mu_1)+(r(sd)))

use "intermediate_data/combined_genderspokes_ratio_ravg_dta.dta", clear
drop if v3==""
drop if v3=="(2)"
drop if v3=="se"
destring v2 v3, replace
replace v1="Majority Male" if v1=="1.condition_2f"
replace v1="Majority Female" if v1=="0bn.condition_2f"
gen ci=v3*1.96
export delimited "intermediate_data/combined_genderspokes_ratio_ravg_forgraphing.csv", replace

***Figure 1C***

**Study 1 Analysis
foreach var in genderminfl_f2avg_ratio genderlinfl_f2avg_ratio {
	use "figure_1_dataset_1.dta", clear
	reg `var' b3.fall_condition if fall_condition~=2, robust
	margins fall_condition, post
	estimates store margins
	test _b[1bn.fall_condition] = _b[3.fall_condition]
	outreg2 margins using "intermediate_data/study1_group`var'", replace dta side noparen noas

	ttest `var' if fall_condition==1 | fall_condition==3, by(fall_condition)
	putexcel set "intermediate_data/study1_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = 1.75

	use "intermediate_data/study1_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1bn.fall_condition"
	replace v1="Majority Female" if v1=="3.fall_condition"
	gen ci=v3*1.96
	export delimited "intermediate_data/study1_group`var'_forgraphing.csv", replace
}


**Study 2 Analysis
foreach var in femvotesminfl_avgpre_ratio femvoteslinfl_avgpre_ratio {
use "figure_1_dataset_2.dta", clear
	drop if genderminfl_ratio_r1 == .
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/study2_group`var'", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/study2_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (r(mu_1)+(r(sd)))
	*putexcel save

	use "intermediate_data/study2_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/study2_group`var'_forgraphing.csv", replace
}


**Combined Analysis
foreach var in femvotesminfl_avgpre_ratio femvoteslinfl_avgpre_ratio {
	use "figure_1_dataset_3.dta", clear
	drop if genderminfl_ratio_ravg == .
	reg `var' i.condition_2f, robust
	margins condition_2f, post
	estimates store margins
	test _b[1.condition_2f] = _b[0.condition_2f]
	outreg2 margins using "intermediate_data/combined_group`var'", replace dta side noparen noas

	ttest `var' if condition_2f==0 | condition_2f==1, by(condition_2f)
	putexcel set "intermediate_data/combined_group`var'_4p.xlsx", sheet("t_test") replace
	putexcel A1=("group1") B1= ("group2") C1=("p") D1=("y.position")
	putexcel A2 = (0.75)
	putexcel B2 = (2.25)
	putexcel C2 = (round(r(p), 0.001))
	putexcel D2 = (r(mu_1)+(r(sd)))
	*putexcel save

	use "intermediate_data/combined_group`var'_dta.dta", clear
	drop if v3==""
	drop if v3=="(2)"
	drop if v3=="se"
	destring v2 v3, replace
	replace v1="Majority Male" if v1=="1.condition_2f"
	replace v1="Majority Female" if v1=="0bn.condition_2f"
	gen ci=v3*1.96
	export delimited "intermediate_data/combined_group`var'_forgraphing.csv", replace
}






